package at.fhooe.stefanirndorfer.game;

import java.io.FileNotFoundException;

import org.lwjgl.LWJGLException;

import at.fhooe.stefanirndorfer.entity.EntityManager;
import at.fhooe.stefanirndorfer.event.EventManager;
import at.fhooe.stefanirndorfer.event.QueuedDispatchStrategy;
import at.fhooe.stefanirndorfer.event.SaveListenerStrategy;
import at.fhooe.stefanirndorfer.graphics.RenderManager;
import at.fhooe.stefanirndorfer.graphics.Window;
import at.fhooe.stefanirndorfer.input.InputManager;
import at.fhooe.stefanirndorfer.quadtree.QuadTree;
import at.fhooe.stefanirndorfer.resources.ResLoader;
import at.fhooe.stefanirndorfer.timer.Timer;
import at.fhooe.stefanirndorfer.walls.GeometrySetups;



public class Game {

	private static int W_WIDTH = 1024;
	private static int W_HEIGHT = 768;
	
	private static Game instance = null;
	
	private Window window;
	private Timer timer;
	private RenderManager render_manager;
	private InputManager input_manager;
	private EntityManager entity_manager;
	private EventManager event_manager;
	private ResLoader resource_loader;
	
	


	private Game() throws LWJGLException, FileNotFoundException {
		timer = new Timer();
		input_manager = new InputManager(W_WIDTH, W_HEIGHT);
		render_manager = new RenderManager();
		entity_manager = new EntityManager();
		resource_loader = new ResLoader();
		event_manager = new EventManager(new QueuedDispatchStrategy(), new SaveListenerStrategy());
		
		window = new Window(W_WIDTH, W_HEIGHT, "Quad-Tree-Demo",this);
		
	}

	
	public static Game getInstance() {
		if (instance == null) {
			try {
				instance = new Game();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (LWJGLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("Hallo, die Game-Instanz wurde erstellt");
		}
		return instance;
	}
	
	
	public void invokeGameLoop(){
		try {
			try {
				window.openWindow();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (LWJGLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	///////////////////////////////////////////////////////////////////////
	///// GETTERS AND SETTERS
	///////////////////////////////////////////////////////////////////////
	
	
	
	public Window getWindow() {
		return window;
	}

	public ResLoader getResource_loader() {
		return resource_loader;
	}


	public void setResource_loader(ResLoader resource_loader) {
		this.resource_loader = resource_loader;
	}


	public EventManager getEvent_manager() {
		return event_manager;
	}


	public void setEvent_manager(EventManager event_manager) {
		this.event_manager = event_manager;
	}


	public void setWindow(Window window) {
		this.window = window;
	}


	public RenderManager getRenderManager() {
		return render_manager;
	}

	public void setRenderManager(RenderManager render_manager) {
		this.render_manager = render_manager;
	}



	public InputManager getInputManager() {
		return input_manager;
	}


	public EntityManager getEntityManager() {
		return entity_manager;
	}
	
	public Timer getTimer(){
		return timer;
	}


}
